package com.kgc.springboot.aviation.controller.liuxu;


import com.github.pagehelper.PageInfo;
import com.kgc.springboot.aviation.mapper.DirectoryMapper;
import com.kgc.springboot.aviation.pojo.*;

import com.kgc.springboot.aviation.service.jianghongkun.LawsService;
import com.kgc.springboot.aviation.service.lvwenjia.ClauseService;
import com.kgc.springboot.aviation.service.lvwenjia.LawsServices;
import com.kgc.springboot.aviation.service.zzy.AllService;

import com.kgc.springboot.aviation.service.zzy.MenuServices;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import java.io.IOException;
import java.util.List;


@Controller
public class controller {
    @Resource
    AllService allService;
    @Resource
    LawsService lawsService;

    @Resource
    ClauseService clauseService;

    @Resource
    MenuServices menuServices;

    @Resource
    DirectoryMapper directoryMapper;


    @RequestMapping("/www")
    public String bbbb(Model model, HttpServletResponse response, @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, @RequestParam(value = "id", required = false, defaultValue = "0") Integer id) throws IOException {

        System.out.println("1231231");
        Integer pageSize = 10;
        PageInfo<Directory> pageInfo = allService.selectAll(pageNum, pageSize, id);

        model.addAttribute("pageInfo", pageInfo);
        Laws laws = lawsService.selectByKey(id);
        model.addAttribute("laws", laws);


        return "菜单管理";
    }

    @RequestMapping("/rrr")
    public String ddd(@RequestParam(value = "id", required = false, defaultValue = "0") Integer id, @RequestParam(value = "ids", required = false, defaultValue = "0") Integer ids,@RequestParam(value = "lawsId", required = false, defaultValue = "0") Integer lawsId, Model model, HttpSession session) {
        System.out.println("lawsId===" + lawsId);
        model.addAttribute("lawsId", lawsId);

        System.out.println(id);
        Directory directory = directoryMapper.selectByPrimaryKey(id);

        model.addAttribute("directory", directory);


        Menu menu = menuServices.getAll(ids);
        model.addAttribute("menu", menu);


        Clause clause = clauseService.getAll(ids);
        model.addAttribute("clause", clause);


        //等用户session
        /*  session.getAttribute("");*/

        //判断该条款是否已经收藏
        PageInfo<Collection> pageInfo = allService.selectCollection(1, 100, 1);
        List<Collection> list = pageInfo.getList();
        Boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getClauseId() == clause.getId()) {
                flag = true;
            }
        }
        model.addAttribute("flag", flag);

        return "菜单条款界面";
    }

    @RequestMapping("/ppp")
    public String ppp(Model model, HttpSession session) {
        List<Laws> all = lawsService.getAll();

            /*  目前没有用户session 默认1
        User user = (User) session.getAttribute("user");
        PageInfo<Collection> pageInfo = allService.selectCollection(1, 100,user.getId());*/
        PageInfo<Collection> pageInfo = allService.selectCollection(1, 100, 1);

        String a = "";
        String b = "";
        String c = "";
        String d = "";

        if (pageInfo.getList().size() > 3) {
            a = pageInfo.getList().get(0).getLaws().getLawsName();
            b = pageInfo.getList().get(1).getLaws().getLawsName();
            c = pageInfo.getList().get(2).getLaws().getLawsName();
            d = pageInfo.getList().get(3).getLaws().getLawsName();
        } else if (pageInfo.getList().size() > 2) {
            a = pageInfo.getList().get(0).getLaws().getLawsName();
            b = pageInfo.getList().get(1).getLaws().getLawsName();
            c = pageInfo.getList().get(2).getLaws().getLawsName();
        } else if (pageInfo.getList().size() > 1) {
            a = pageInfo.getList().get(0).getLaws().getLawsName();
            b = pageInfo.getList().get(1).getLaws().getLawsName();
        } else if (pageInfo.getList().size() > 0) {
            a = pageInfo.getList().get(0).getLaws().getLawsName();
        }
        model.addAttribute("a", a);
        model.addAttribute("b", b);
        model.addAttribute("c", c);
        model.addAttribute("d", d);
        model.addAttribute("all", all);
        return "index";
    }

    @RequestMapping("/ooo")
    public String test00(){
        return "user";
    }
    @RequestMapping("/uuu")
    public String test0000(){

        return "index2";
    }
}
